package GUILayer;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import ModelLayer.Customer;

public class CustomerTableModel  extends AbstractTableModel {
	private ArrayList<Customer> li = new ArrayList<Customer>();
	private String[] columnNames = { "Name", "Address",
			"Codezip", "City", "PhoneNo", "Email", "Cpr/Cvr"};

	public CustomerTableModel(){
	}
	
	public void PopulateList(ArrayList<Customer> list)
	{
		if(list != null)
		{
			this.li = list;
		}
	}
	
	public void fireTableDataChanged()
	{
		fireTableDataChanged();
	}

	@Override
	public String getColumnName(int columnIndex){
		return columnNames[columnIndex];
	}

	@Override     
	public int getRowCount() {
		return li.size();
	}

	@Override        
	public int getColumnCount() {
		return 7; 
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Customer c = li.get(rowIndex);
		switch (columnIndex) {
		case 0: 
			return c.getName();
		case 1:
			return c.getAddress();
		case 2:
			return c.getCodeZip();
		case 3:
			return c.getCity();
		case 4:
			return c.getPhoneNo();
		case 5:
			return c.getEmail();
		case 6:
			return c.getCprCvr(); 
		}
		return null;
	}

	@Override
	public Class<?> getColumnClass(int columnIndex){
		switch (columnIndex){
		case 0:
			return Integer.class;
		case 1:
			return String.class;
		case 2:
			return String.class;
		case 3:
			return String.class;
		case 4:
			return String.class;
		case 5:
			return String.class;
		case 6:
			return String.class;
		}
		return null;
	}
}